package com.ruoyi.business.controller;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.ruoyi.business.domain.CourseVideo;
import com.ruoyi.business.domain.bo.CourseVideoBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.service.ICourseVideoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小节视频Controller
 * 
 * @author 最爱喝兽奶
 * @date 2022-08-02
 */
@RestController
@RequestMapping("/business/courseVideo")
public class CourseVideoController extends BaseController
{
    @Autowired
    private ICourseVideoService courseVideoService;

    /**
     * 查询小节视频列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CourseVideoBo bo)
    {
        return courseVideoService.selectCourseVideoList(bo);
    }

    /**
     * 导出小节视频列表
     */
    @Log(title = "小节视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseVideoBo bo)
    {
//        List<CourseVideo> list = CourseVideoService.selectCourseVideoList(bo);
//        ExcelUtil<CourseVideo> util = new ExcelUtil<CourseVideo>(CourseVideo.class);
//        util.exportExcel(response, list, "小节视频数据");
    }

    /**
     * 获取小节视频详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(courseVideoService.selectCourseVideoById(id));
    }

    /**
     * 新增小节视频
     */
    @Log(title = "小节视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseVideoBo courseVideo)
    {
        courseVideoService.insertCourseVideo(courseVideo);
        return AjaxResult.success();
    }

    /**
     * 修改小节视频
     */
    @Log(title = "小节视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseVideoBo courseVideo)
    {
        courseVideoService.updateCourseVideo(courseVideo);
        return AjaxResult.success();
    }

    /**
     * 删除小节视频
     */
    @Log(title = "小节视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        courseVideoService.deleteCourseVideoByIds(ids);
        return AjaxResult.success();
    }


    /**
     * 小节上移
     * @param id
     * @return
     */
    @GetMapping("/move/up/{id}")
    public AjaxResult moveUp(@NotNull(message = "id不能为空")
                             @PathVariable("id") String id) {
        courseVideoService.moveUp(id);
        return AjaxResult.success();
    }

    /**
     * 小节下移
     * @param id
     * @return
     */
    @GetMapping("/move/down/{id}")
    public AjaxResult moveDown(@NotNull(message = "id不能为空")
                               @PathVariable("id") String id) {
        courseVideoService.moveDown(id);
        return AjaxResult.success();
    }

}
